﻿Imports System.Text
Module Module1
    Declare Function bstrToarr1 Lib "mfcdll" (ByRef vbstr As Object, ByRef p As Single, ByVal n As Integer) As Integer
    Declare Function arrTobstr Lib "mfcdll" (ByRef b As Object, ByRef v As Object, ByVal n As Integer) As Integer
    Public Structure Sig
        Dim xArr As Object
        Dim xn As Integer
        <VBFixedArray(4)> Dim yArr() As Object
        <VBFixedArray(4)> Dim yn() As Integer
        <VBFixedArray(4)> Dim stoped() As Boolean
        <VBFixedArray(4)> Dim Aborted() As Boolean

        Public Sub Initialize()
            ReDim yArr(4)
            ReDim yn(4)
            ReDim stoped(4)
            ReDim Aborted(4)
        End Sub
    End Structure
    Public Function SingleArrTobyteArr(ByRef v As Object, ByRef n As Integer) As Byte()
        Dim b() As Byte
        ReDim b(1)
        ''Dim r As Integer
        'If n < 1 Then
        '    Return b
        'Else
        '    ReDim b(4 * n)
        '    'mymemcpy(b(0), v, n * 4)
        '    arrTobstr(b, v, n)
        'End If
        Return b
    End Function
    Public Sub savesignew_memo(ByRef session As NHibernate.ISession, ByRef mysig As Sig, ByVal sid As Integer)
        'Dim v As New NCS.VoltNew
        'v.cvoltArr = (New UnicodeEncoding()).GetString(SingleArrTobyteArr(mysig.yArr(0), mysig.yn(0)), 0, mysig.yn(0))
        'v.svoltArr = (New UnicodeEncoding()).GetString(SingleArrTobyteArr(mysig.yArr(1), mysig.yn(1)), 0, mysig.yn(0))
        'v.c2voltArr = (New UnicodeEncoding()).GetString(SingleArrTobyteArr(mysig.yArr(2), mysig.yn(2)), 0, mysig.yn(0))
        'v.s2voltArr = (New UnicodeEncoding()).GetString(SingleArrTobyteArr(mysig.yArr(3), mysig.yn(3)), 0, mysig.yn(0))
        'v.mtimeArr = (New UnicodeEncoding()).GetString(SingleArrTobyteArr(mysig.xArr, mysig.xn), 0, mysig.yn(0))
        'v.xn = mysig.xn
        'v.yn0 = mysig.yn(0)
        'v.yn1 = mysig.yn(1)
        'v.yn2 = mysig.yn(2)
        'v.yn3 = mysig.yn(3)
        'v.sampleid = sid
        'session.Save(v)
        'session.Flush()
    End Sub
    Public Sub savesignew(ByRef session As NHibernate.ISession, ByRef mysig As Sig, ByVal sid As Integer)
        Dim v As New NCS.VoltNew
        v.cvoltArr = SingleArrTobyteArr(mysig.yArr(0), mysig.yn(0))
        v.svoltArr = SingleArrTobyteArr(mysig.yArr(1), mysig.yn(1))
        v.c2voltArr = SingleArrTobyteArr(mysig.yArr(2), mysig.yn(2))
        v.s2voltArr = SingleArrTobyteArr(mysig.yArr(3), mysig.yn(3))
        v.mtimeArr = SingleArrTobyteArr(mysig.xArr, mysig.xn)
        v.xn = mysig.xn
        v.yn0 = mysig.yn(0)
        v.yn1 = mysig.yn(1)
        v.yn2 = mysig.yn(2)
        v.yn3 = mysig.yn(3)
        v.sampleid = sid
        session.Save(v)
        session.Flush()
    End Sub
    Public Sub loadsignew_memo(ByRef session As NHibernate.ISession, ByRef mysig As Sig, ByVal sid As Integer)
        'Dim v As NCS.VoltNew
        'v = TryCast(session.Get(GetType(NCS.VoltNew), sid), NCS.VoltNew)
        'If Not v Is Nothing Then
        '    mysig.xn = v.xn
        '    mysig.yn(0) = v.yn0
        '    mysig.yn(1) = v.yn1
        '    mysig.yn(2) = v.yn2
        '    mysig.yn(3) = v.yn3
        '    bytearrtoSingleArr(v.mtimeArr, mysig.xArr, mysig.xn)
        '    bytearrtoSingleArr(v.cvoltArr, mysig.yArr(0), mysig.xn)
        '    bytearrtoSingleArr(v.svoltArr, mysig.yArr(1), mysig.xn)
        '    bytearrtoSingleArr(v.c2voltArr, mysig.yArr(2), mysig.xn)
        '    bytearrtoSingleArr(v.s2voltArr, mysig.yArr(3), mysig.xn)
        'End If
    End Sub
    Public Sub loadsignew(ByRef session As NHibernate.ISession, ByRef mysig As Sig, ByVal sid As Integer)
        Dim v As NCS.VoltNew
        v = TryCast(session.Get(GetType(NCS.VoltNew), sid), NCS.VoltNew)
        If Not v Is Nothing Then
            mysig.xn = v.xn
            mysig.yn(0) = v.yn0
            mysig.yn(1) = v.yn1
            mysig.yn(2) = v.yn2
            mysig.yn(3) = v.yn3
            bytearrtoSingleArr(v.mtimeArr, mysig.xArr, mysig.xn)
            bytearrtoSingleArr(v.cvoltArr, mysig.yArr(0), mysig.xn)
            bytearrtoSingleArr(v.svoltArr, mysig.yArr(1), mysig.xn)
            bytearrtoSingleArr(v.c2voltArr, mysig.yArr(2), mysig.xn)
            bytearrtoSingleArr(v.s2voltArr, mysig.yArr(3), mysig.xn)
        End If
    End Sub
    Sub bytearrtoSingleArr(ByRef bytetmp As Byte(), ByRef v As Object, ByVal n As Integer)
        'If n < 1 Then Exit Sub
        'Dim x() As Double
        'ReDim x(n - 1)
        'Dim n1 As Integer
        'mymemcpy(x(0), bytetmp, n * 4)
        'bstrToarr1(bytetmp, x(0), n)

        'v = x
    End Sub
End Module
